﻿<%@ Page Title="Manage Environments" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="ManageEnvironments.aspx.cs" Inherits="NIntegrate.Configuration.UI.ManageEnvironments" MaintainScrollPositionOnPostback="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2>Manage Environments</h2>
    <div class="bottomhyperlink"><img alt="Add new environment" src="Images/plus.gif" /><asp:LinkButton 
            ID="btnShowAddNewPanel" runat="server" Text="Add new environment" 
            onclick="btnShowAddNewPanel_Click"></asp:LinkButton></div>
    <br />
    <asp:GridView CssClass="gridview"
        ID="gvEnvironments" runat="server" 
        DataSourceID="dsEnvironments"
        DataKeyNames="Environment_id"
        AllowSorting="true"
        AutoGenerateDeleteButton="true"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true" onrowcommand="gvEnvironments_RowCommand">
        <Columns>
            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                <ItemTemplate>
                    <%#Eval("Name") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbName" runat="server" MaxLength="50" Text='<%#Bind("Name") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="tbNameRequired" runat="server"
                        ControlToValidate="tbName" EnableClientScript="false"
                        ErrorMessage="Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="Description" DataField="Description" SortExpression="Description" />
            <asp:TemplateField HeaderText="Farms">
                <ItemTemplate>
                    <asp:LinkButton ID="btnViewFarms" runat="server" Text="View" CommandName="Select" CommandArgument='<%# "ViewFarms|" + Eval("Environment_id") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ConnectionStrings">
                <ItemTemplate>
                    <asp:LinkButton ID="btnViewConnectionStrings" runat="server" Text="View" CommandName="Select" CommandArgument='<%# "ViewConnectionStrings|" + Eval("Environment_id") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <SelectedRowStyle BackColor="LightYellow" />
    </asp:GridView>
    <asp:Panel ID="panelBottom" runat="server" CssClass="panelBottom">
        <asp:DetailsView ID="dvAddEnvironment" runat="server" Visible="false"
            DataSourceID="dsEnvironments" DefaultMode="Insert"
            AutoGenerateRows="false"
            AutoGenerateInsertButton="true"
            CssClass="detailstable" onitemcommand="dvAddEnvironment_ItemCommand" 
            oniteminserted="dvAddEnvironment_ItemInserted">
            <Fields>
                <asp:TemplateField HeaderText="Name">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbName" runat="server" Text='<%#Bind("Name") %>' MaxLength="50"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="tbNameRequired" runat="server"
                            ControlToValidate="tbName" EnableClientScript="false"
                            ErrorMessage="Required"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Description" DataField="Description" />
            </Fields>
        </asp:DetailsView>
        <asp:GridView CssClass="gridview" Visible="false"
            ID="gvFarms" runat="server" 
            DataSourceID="dsFarms"
            AllowSorting="true"
            AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField HeaderText="FarmName" DataField="FarmName" SortExpression="FarmName" />
                <asp:BoundField HeaderText="FarmAddress" DataField="FarmAddress" SortExpression="FarmAddress" />
            </Columns>
        </asp:GridView>        
        <asp:GridView CssClass="gridview" Visible="false"
            ID="gvConnectionStrings" runat="server" 
            DataSourceID="dsConnectionStrings"
            AllowSorting="true"
            AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name" />
                <asp:BoundField HeaderText="Value" DataField="Value" SortExpression="Value" />
                <asp:BoundField HeaderText="ProviderName" DataField="ProviderName" SortExpression="ProviderName" />
            </Columns>
        </asp:GridView>        
    </asp:Panel>
    <ni:QueryDataSource ID="dsEnvironments" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsFarms" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>    
    <ni:QueryDataSource ID="dsConnectionStrings" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
</asp:Content>
